﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Yappi.Tests
{
    /// <summary>
    /// Сводное описание для UnitTest1
    /// </summary>
    [TestClass]
    public class PerformanceTest
    {
        private static readonly int Iterations = 300000000;
        public PerformanceTest()
        {
            //
            // TODO: добавьте здесь логику конструктора
            //
        }


        #region Дополнительные атрибуты тестирования
        //
        // При написании тестов можно использовать следующие дополнительные атрибуты:
        //
        // ClassInitialize используется для выполнения кода до запуска первого теста в классе
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // ClassCleanup используется для выполнения кода после завершения работы всех тестов в классе
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //

        //
        #endregion

        private ManualINPC manualInstance;

        private AutoOverrideINPC autoInstance;

        //TestInitialize используется для выполнения кода перед запуском каждого теста 
        [TestInitialize]
        public void TestInitialize()
        {
            manualInstance = new ManualINPC();
            autoInstance = AutoOverrideINPC.Constructor<Func<AutoOverrideINPC>>.New();

            manualInstance.PropertyChanged += (i, a) => { };
            autoInstance.PropertyChanged+= (i, a) => { };
            EmptyRun();
            var ivalue = 256;
            var ovalue = new object();
            var svalue = "test";
            for (int i = 0; i < 1000; i++)
            {
                new ManualINPC(ivalue, ovalue, svalue);
                new ManualINPC();
                AutoOverrideINPC.Constructor<Func<AutoOverrideINPC>>.New();
                AutoOverrideINPC.Constructor<Func<int, object, string, AutoOverrideINPC>>.New(ivalue, ovalue, svalue);
            }
        }

        //TestCleanup используется для выполнения кода после завершения каждого теста
        [TestCleanup]
        public void TestCleanup() { }

        [TestMethod]
        public void EmptyRun()
        {
            var ivalue = 256;
            var ovalue = new object();
            var svalue = "test";
            var counter = 0;
            for (counter = 0; counter < Iterations; counter++)
            {
                
            }
        }

        [TestMethod]
        public void ManualImplementationComplexCtorRun()
        {
            var ivalue = 256;
            var ovalue = new object();
            var svalue = "test";
            var counter = 0;
            for (counter = 0; counter < Iterations; counter++)
            {
                new ManualINPC(ivalue, ovalue, svalue);
            }
        }
        [TestMethod]
        public void ManualImplementationDefaultCtorRun()
        {
            var ivalue = 256;
            var ovalue = new object();
            var svalue = "test";
            var counter = 0;
            for (counter = 0; counter < Iterations; counter++)
            {
                new ManualINPC();
            }
        }
        [TestMethod]
        public void AutoImplementationComplexCtorRun()
        {
            var ivalue = 256;
            var ovalue = new object();
            var svalue = "test";
            var counter = 0;
            for (counter = 0; counter < Iterations; counter++)
            {
                AutoOverrideINPC.Constructor<Func<int, object, string, AutoOverrideINPC>>.New(ivalue, ovalue, svalue);
            }
        }
        [TestMethod]
        public void AutoImplementationDefaultCtorRun()
        {
            var ivalue = 256;
            var ovalue = new object();
            var svalue = "test";
            var counter = 0;
            for (counter = 0; counter < Iterations; counter++)
            {
                AutoOverrideINPC.Constructor<Func<AutoOverrideINPC>>.New();
            }
        }

        [TestMethod]
        public void ManualImplementationPropertyIntWriteAccessRun()
        {
            var ivalue = 256;
            var ovalue = new object();
            var svalue = "test";
            var counter = 0;
            for (counter = 0; counter < Iterations; counter++)
            {
                manualInstance.IntProperty = counter;
            }
        }

        [TestMethod]
        public void AutoImplementationPropertyIntWriteAccessRun()
        {
            var ivalue = 256;
            var ovalue = new object();
            var svalue = "test";
            var counter = 0;
            for (counter = 0; counter < Iterations; counter++)
            {
                autoInstance.IntProperty = counter;
            }
        }
        [TestMethod]
        public void ManualImplementationIntPropertyReadAccessRun()
        {
            var ivalue = 256;
            var ovalue = new object();
            var svalue = "test";
            var counter = 0;
            for (counter = 0; counter < Iterations; counter++)
            {
                ivalue = manualInstance.IntProperty;
            }
        }

        [TestMethod]
        public void AutoImplementationIntPropertyReadAccessRun()
        {
            var ivalue = 256;
            var ovalue = new object();
            var svalue = "test";
            var counter = 0;
            for (counter = 0; counter < Iterations; counter++)
            {
                ivalue = autoInstance.IntProperty;
            }
        }
        [TestMethod]
        public void ManualImplementationPropertyStringWriteAccessRun()
        {
            var ivalue = 256;
            var ovalue = new object();
            var svalue = "test";
            var counter = 0;
            for (counter = 0; counter < Iterations; counter++)
            {
                manualInstance.StringProperty = counter.ToString();
            }
        }

        [TestMethod]
        public void AutoImplementationPropertyStringWriteAccessRun()
        {
            var ivalue = 256;
            var ovalue = new object();
            var svalue = "test";
            var counter = 0;
            for (counter = 0; counter < Iterations; counter++)
            {
                autoInstance.StringProperty = counter.ToString();
            }
        }
        [TestMethod]
        public void ManualImplementationStringPropertyReadAccessRun()
        {
            var ivalue = 256;
            var ovalue = new object();
            var svalue = "test";
            var counter = 0;
            for (counter = 0; counter < Iterations; counter++)
            {
                svalue = manualInstance.StringProperty;
            }
        }

        [TestMethod]
        public void AutoImplementationStringPropertyReadAccessRun()
        {
            var ivalue = 256;
            var ovalue = new object();
            var svalue = "test";
            var counter = 0;
            for (counter = 0; counter < Iterations; counter++)
            {
                svalue = autoInstance.StringProperty;
            }
        }
    }
}
